﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MediatR;
using SystemHYS.API.Application.command.ProductionOrdersCommand;
using SystemHYS.Domian.DTO;
using SystemHYS.Domian;
using SystemHYS.API.DTOS;
using SystemHYS.API.Application.command.ProductionRequisitionCommand;
namespace SystemHYS.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionRequisitionController : ControllerBase
    {
        IMediator mediator;
        public ProductionRequisitionController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加领料信息
        /// </summary>
        /// <param name="command">领料信息</param>、    
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> AddProductionRequisition(ProductionRequisitionCreateCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 领料信息
        /// </summary>
        /// <param name="command">查询条件</param>
        /// <returns>领料信息</returns>
        [HttpGet]
        public async Task<Apiresult<List<ProductionRequisitionDTO>>> GetProductionRequisition([FromQuery] ProductionRequisitionShowCommand command)
        {
            Apiresult<List<ProductionRequisitionDTO>> apiresult = new Apiresult<List<ProductionRequisitionDTO>>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        
        /// <summary>
        /// 修改领料信息
        /// </summary>
        /// <param name="command">领料信息</param>、    
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> UpdateProductionRequisition(ProductionRequisitionUpdateCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 删除领料信息
        /// </summary>
        /// <param name="command">领料Id</param>
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> DeleteProductionRequisition(ProductionRequisitionDeleteCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 领料信息
        /// </summary>
        /// <param name="command">查询条件</param>
        /// <returns>领料信息</returns>
        [HttpGet]
        public async Task<Apiresult<ProductionRequisitionShowDTO>> GetProductionRequisitionModel([FromQuery] ProductionRequisitionModelCommand command)
        {
            Apiresult<ProductionRequisitionShowDTO> apiresult = new Apiresult<ProductionRequisitionShowDTO>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
    }
}
